import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:flutter_project/config/app_bar_view.dart';
import 'package:flutter_project/config/theme_color.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart';

class UserEditInfo extends StatelessWidget {
  UserEditInfo({super.key});

  final ValueNotifier<String> timeStr = ValueNotifier<String>('2012-12-30');

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppBar(
      title: '个人资料',
      childWidget: ListView(
        children: [
          const SizedBox(
            height: 14,
          ),
          getUserAvatar(),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          getUserSex(leftName: '性别', rightName: isMan ? '男' : '女'),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          getUserSex(leftName: '手机号', rightName: '1511352090'),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          GestureDetector(
              onTap: () {
                DatePicker.showDatePicker(context,
                    currentTime: DateTime.now(),
                    showTitleActions: true,
                    minTime: DateTime(1970, 1, 1),
                    maxTime: DateTime(2030, 1, 1), onChanged: (date) {
                  debugPrint('change $date');
                }, onConfirm: (date) {
                  debugPrint('confirm $date');
                  timeStr.value = formatDate(date, [yyyy, '-', mm, '-', dd]);
                }, locale: LocaleType.zh);
              },
              child: ValueListenableBuilder(
                  valueListenable: timeStr,
                  builder: (BuildContext context, String value, Widget? child) {
                    return getUserSex(leftName: '生日', rightName: value);
                  })),
        ],
      ),
    );
  }

  Widget getUserAvatar() {
    String sexStr = 'assets/images/as_avatar_man.png';
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          const Text('头像'),
          Image.asset(
            sexStr,
            width: 60,
          ),
        ],
      ),
    );
  }

  bool get isMan {
    return true;
  }

  Widget getUserSex({
    required String leftName,
    required String rightName,
  }) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(leftName),
          Text(rightName),
        ],
      ),
    );
  }
}
